--- title: "STAT 513 fa 2018 hw XX" author: "YOUR NAME HERE" date: "THE DATE HERE" output: pdf_document: default html_document: default --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` # 1. a) $H_0$: $p = 1/6$ versus $H_1$: $p \neq 1/6$ b) $H_0$: $p \leq 1/6$ versus $H_1$: $p > 1/6$ c) $H_0$: $p \geq 1/6$ versus $H_1$: $p < 1/6$ d) i) Flip the coin very many times; if "heads"" turns up close to half the time, it seems to support the claim; however, someone could always say, "well, maybe the probability of heads is $0.5001$." ii) Even if from a very large number of tosses "heads" comes up close to half the time, one can never defend a claim that the coin is perfectly balanced: an objector can always posit that the true probability of "heads" is $0.50001$ or $0.5000001$, and then one has to do more tosses \emph{ad infinitum}. Thus it is easier to collect evidence against the claim of balancedness than in favor of it. # 2. a) $H_0$: $p=1/2$ versus $H_0$: $p \neq 1/2$. b) i) `sum(dbinom(8:10,10,.6),dbinom(0:2,10,.6))=0.1795843` ii) `1-sum(dbinom(8:10,10,.3),dbinom(0:2,10,.3))}= 0.6156268` iii) $\gamma(p) = \sum_{y=0}^2{ 10 \choose y }p^y(1-p)^{10-y} + \sum_{y=8}^{10}{ 10 \choose y }p^y(1-p)^{10-y}$ iv) The size is $$ \begin{aligned}\gamma(1/2) &= \sum_{y=0}^2{ 10 \choose y }(1/2)^y(1-1/2)^{10-y} + \sum_{y=8}^{10}{ 10 \choose y }(1/2)^y(1-1/2)^{10-y}\\ &=\texttt{sum(dbinom(0:2,10,.5),dbinom(8:10,10,.5))}\\ &= 0.109375. \end{aligned} $$ v) The code below plots the power curve. vi) The power is equal to the size at $p=1/2$, which is the value of $p$ specified in the null hypothesis. ```{r} p.seq <- seq(.01,.99,length=99) power <- numeric() for(j in 1:99) { power[j] <- sum(dbinom(0:2,10,p.seq[j]),dbinom(8:10,10,p.seq[j])) } plot(p.seq,power,type="l",ylim=c(0,1),xlab="p") abline(v=0.5,lty=3) # vert line at null value abline(h=0.109375,lty=3)# horiz line at size ``` c) Consider tests of the form $$ \text{Reject $H_0$ iff $X_1+\dots+X_{20} \in \mathcal{R}$} $$ for different rejection regions $\mathcal{R}$. One option is to choose $$ \mathcal{R} = \{0,1,2,3,4,5\}\cup\{15,16,17,18,19,20\}, $$ with which the test has size $$ \texttt{sum(dbinom(0:5,20,.5),dbinom(15:20,20,.5))} = 0.04138947 < 0.05 $$ d) The following code plots the power curve. ```{r} p.seq <- seq(.01,.99,length=99) power <- numeric() for(j in 1:99) { power[j] <- sum(dbinom(0:5,20,p.seq[j]),dbinom(15:20,20,p.seq[j])) } plot(p.seq,power,type="l",ylim=c(0,1),xlab="p") abline(v=0.5,lty=3) # vert line at null value abline(h=0.05,lty=3) # horiz line at max. allowed size ```